package com.tanhua.server.controller;

import com.tanhua.domain.vo.MomentVo;
import com.tanhua.domain.vo.PageResult;
import com.tanhua.domain.vo.PublishVo;
import com.tanhua.domain.vo.VisitorVo;
import com.tanhua.server.service.MomentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/movements")
public class MomentController {
    @Autowired
    private MomentService momentService;

    @PostMapping
    public ResponseEntity postMoment(PublishVo publishVo, MultipartFile[] imageContent) {
        momentService.postMoment(publishVo, imageContent);
        return ResponseEntity.ok(null);
    }

    @GetMapping
    public ResponseEntity getMoment(@RequestParam(value = "page", defaultValue = "1") Long page, @RequestParam(value = "pagesize", defaultValue = "10") Long pagesize) {
        PageResult<MomentVo> pageResult = momentService.getMoment(page, pagesize);
        return ResponseEntity.ok(pageResult);
    }

    @GetMapping("/recommend")
    public ResponseEntity recomMoment(@RequestParam(value = "page", defaultValue = "1") Long page, @RequestParam(value = "pagesize", defaultValue = "10") Long pagesize) {
        PageResult<MomentVo> pageResult = momentService.recomMoment(page, pagesize);
        return ResponseEntity.ok(pageResult);
    }

    @GetMapping("/all")
    public ResponseEntity queryMyPublishList(@RequestParam(value = "page",defaultValue = "1") Long page,@RequestParam(value = "pagesize",defaultValue = "10") Long pagesize,Long userId){
      PageResult<MomentVo> pageResult=  momentService.queryMyPublishList(page,pagesize,userId);
      return ResponseEntity.ok(pageResult);
    }
    @GetMapping("/{publishId}/like")
    public ResponseEntity like(@PathVariable String publishId){
        int likeCount=  momentService.like(publishId);
        return ResponseEntity.ok(likeCount);
    }
    @GetMapping("/{publishId}/dislike")
    public ResponseEntity dislike(@PathVariable String publishId){
        int likeCount=  momentService.dislike(publishId);
        return ResponseEntity.ok(likeCount);
    }
    @GetMapping("/{publishId}/love")
    public ResponseEntity love(@PathVariable String publishId){
        int loveCount=  momentService.love(publishId);
        return ResponseEntity.ok(loveCount);
    }
    @GetMapping("/{publishId}/unlove")
    public ResponseEntity unlove(@PathVariable String publishId){
        int loveCount=  momentService.unlove(publishId);
        return ResponseEntity.ok(loveCount);
    }
    @GetMapping("/visitors")
    public ResponseEntity visitors(){
       List<VisitorVo> visitorVoList= momentService.visitors();
        return ResponseEntity.ok(visitorVoList);
    }
    @GetMapping("/{publishId}")
    public ResponseEntity queryMyPublishList(@PathVariable String publishId){
        MomentVo momentVo=  momentService.findPublishById(publishId);
        return ResponseEntity.ok(momentVo);
    }
}
